<template>
    <div
        class="queue-progress-container rr-ignore"
        id="ivcs-queue-progress-container"
    >
        <!-- 排队页面，”迈瑞实时音视频服务“去掉 -->
        <!-- <div class="title"></div> -->
        <div class="postion-container">
            <div class="postion-wrapper">
                <div class="icon"></div>
                <p class="queue-box" v-if="!progressTitle">
                    <!-- 正在为您呼叫工程师，您前面还有x位，请您耐心等待 -->
                    <!-- 正在为您呼叫，您前面还有1位在排队，请稍等... -->
                    <span class="label">正在为您呼叫，您前面还有 </span>
                    <span class="number">{{ currentPosition }}</span>
                    <span class="label"> 位在排队，请稍等...</span>
                    <span class="loading"></span>
                </p>
                <p class="queue-title-box" v-if="progressTitle">
                    <span class="label" v-if="progressTitle">{{ progressTitle }} </span>
                </p>
                <div @click="hangup" class="hangup-btn">取消</div>
            </div>
        </div>

        <div class="footer-wrapper" style="filter: blur(9px)"></div>
        <div class="footer">
            <p class="service-call">
                如您有紧急通话需求，请拨打我们的服务热线电话400-700-5652
            </p>
        </div>

        <message-box
            v-if="isMessageBoxShow"
            :title="messageBoxTitle"
            :content="messageBoxContent"
            :onCancel="onMessageBoxCancel"
            :onConfirm="onMessageBoxConfirm"
        />
        <SubmitForm v-if="showSubmitForm" :ticket="ticket" @close="onSubmit" />
    </div>
</template>

<script>
import { mapState } from "vuex";
import MessageBox from "../message-box/MessageBox.vue";
import { return2Main } from "../../lib/util";
import SubmitForm from "../error/SubmitForm.vue";
export default {
    components: { MessageBox, SubmitForm },
    name: "SessionProgress",
    data() {
        return {
            isMessageBoxShow: false,
            messageBoxTitle: "温馨提示",
            messageBoxContent: "确认挂断会话？",
            showSubmitForm: false,
        };
    },
    props: {
        progressTitle: {
            type: String,
            default: () => "",
        },
        waitingNumber: {
            type: Number,
            required: true,
            default: () => 0,
        },
        currentPosition: {
            type: Number,
            required: true,
            default: () => 0,
        },
        // inviteProgressCode: {
        //     type: String,
        //     required: true,
        //     default: () => "",
        // },
        ticket: {
            type: Object,
            default: () => {},
        },
    },
    watch: {
        hangupReason(newValue) {
            if (
                [
                    "cancel",
                    "ringingTimeout",
                    "the specified agent is rejected",
                    "rejected",
                ].includes(newValue)
            ) {
                this.showSubmitForm = true;
            }
        },
    },
    computed: {
        ...mapState("app", ["hangupReason"]),
    },
    mounted() {
        //  刷新页面自动挂断
        window.onunload = function () {
            ivcsCustomer.hangup("page-reload");
            return2Main();
        };
        this.$el.parentNode.removeChild(this.$el);
        document.body.appendChild(this.$el);
    },
    methods: {
        hangup() {
            this.isMessageBoxShow = true;
        },

        onMessageBoxCancel() {
            this.isMessageBoxShow = false;
        },

        onMessageBoxConfirm() {
            this.isMessageBoxShow = false;
            this.$nextTick(() => {
                ivcsCustomer.hangup("cancel");
                setTimeout(() => {
                    this.showSubmitForm = true;
                }, 200);
            });
        },
        onSubmit() {
            this.showSubmitForm = false;
            return2Main();
        },
    },
};
</script>

<style lang="less" scoped>
@media screen and (max-height: 995px) {
}
.queue-progress-container {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("../../assets/img/session-progress-back.png") no-repeat;
    background-size: cover;
    background-position: center;
    pointer-events: auto;
    position: absolute;
    z-index: 1;
    text-align: center;

    .title {
        width: 260px;
        height: 36px;
        background-image: url("../../assets/img/session-progress-title.png");
        background-size: 260px 36px;
        display: inline-block;
        background-position: center;
        background-repeat: no-repeat;
        margin-top: 20px;
    }

    .postion-container {
        width: 100%;
        height: 80px;
        position: fixed;
        bottom: 82px;
        padding: 0 14px;
        box-sizing: border-box;
        z-index: 1;

        .postion-wrapper {
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.9);
            box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.2);
            border-radius: 12px;
            display: flex;
            align-items: center;

            .icon {
                width: 44px;
                height: 44px;
                background-image: url("../../assets/img/call.png");
                background-size: 44px 44px;
                display: inline-block;
                background-position: center;
                background-repeat: no-repeat;
                margin-left: 6px;
                min-width: 44px;
            }

            .queue-box {
                width: auto;
                // height: 42px;
                font-size: 14px;
                font-weight: 400;
                color: #000000;
                line-height: 21px;
                text-align: left;
                margin: 0 6px;
                box-sizing: border-box;

                .number {
                    color: #f43c42;
                }
            }
            .queue-title-box{
                width: 100%;
                font-size: 14px;
                font-weight: 400;
                color: #000000;
                line-height: 21px;
                text-align: left;
                margin: 0 6px;
                box-sizing: border-box;
            }

            .hangup-btn {
                width: 80px;
                height: 32px;
                background: linear-gradient(180deg, #f94248 0%, #c7000b 100%);
                box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.06);
                border-radius: 16px;
                font-size: 13px;
                font-weight: 500;
                color: #ffffff;
                line-height: 32px;
                min-width: 80px;
                margin-right: 12px;
            }
        }
    }

    .footer-wrapper {
        position: fixed;
        bottom: 0;
        width: 100%;
        height: 110px;
        background: #f2e4e5;
        box-shadow: 0px -4px 10px 0px rgba(0, 0, 0, 0.13);
        // border-radius: 20px 20px 0px 0px;
    }
    .footer {
        position: fixed;
        bottom: 0;
        width: 100%;
        height: 110px;
        display: flex;
        justify-content: center;
        align-items: center;

        .service-call {
            font-size: 12px;
            font-weight: 400;
            color: #868383;
            line-height: 18px;
            width: 242px;
        }
    }

    .loading {
        font-size: 14px;
        font-weight: bold;
    }

    .loading:after {
        overflow: hidden;
        display: inline-block;
        vertical-align: bottom;
        -webkit-animation: ellipsis steps(4, end) 1200ms infinite;
        animation: ellipsis steps(4, end) 1200ms infinite;
        content: "\2026"; /* ascii code for the ellipsis character */
        width: 0px;
    }

    @keyframes ellipsis {
        to {
            width: 1.25em;
        }
    }

    @-webkit-keyframes ellipsis {
        to {
            width: 1.25em;
        }
    }
}
</style>

